package com.af.system.resource;

import org.springframework.web.context.ServletContextAware;

import javax.servlet.ServletContext;

/**
 * @author : zhenyun.su
 * @comment :获取版本号值versionValue，contextRoot放入上下文变量中,为前端页面使用
 * @since : 2020-01-19
 * @see AfResourceVersion
 */

public class AfResourceServletContextAware implements ServletContextAware {
    private ServletContext servletContext;
    private String contextRoot;
    private String versionValue;
    private AfResourceVersion afResourceVersion;

    public void init(){
        versionValue= afResourceVersion.getVersionValue();
        this.contextRoot = getServletContext().getContextPath()+"/"+versionValue;
        System.out.println(contextRoot);
        getServletContext().setAttribute(AfResourceVersion.VERSION_CONTEXT_PATH,contextRoot);
    }

    public ServletContext getServletContext() {
        return servletContext;
    }

    @Override
    public void setServletContext(ServletContext servletContext) {
        this.servletContext = servletContext;
    }

    public String getContextRoot() {
        return contextRoot;
    }

    public void setContextRoot(String contextRoot) {
        this.contextRoot = contextRoot;
    }

    public String getVersionValue() {
        return versionValue;
    }

    public void setVersionValue(String versionValue) {
        this.versionValue = versionValue;
    }

    public AfResourceVersion getResourceVersion() {
        return afResourceVersion;
    }

    public void setResourceVersion(AfResourceVersion afResourceVersion) {
        this.afResourceVersion = afResourceVersion;
    }
}
